//引入express模块
const express = require("express");
//引入连接池模块
const pool = require("../pool.js");
//console.log(pool)
//创建路由器对象
const router = express.Router();
//通过用户的uid值获取用户信息的接口
//GET /me
//地址:http://127.0.0.1:3333/me?uid=1
//返回结果
router.post("/", (req, res, next) => {
  var obj = req.body;
  console.log(obj);
  pool.query(
    "select * from hbb_user where uname=? and upwd=?",
    [obj.uname, obj.upwd],
    (err, r) => {
      if (err) {
        //如果SQL中出现错误，交给下一个错误处理中间件
        return next(err);
      }
      console.log(r);
      //结果是数组，如果是空数组登录失败，否则登录成功
      if (r.length === 0) {
        res.send({ code: 400, msg: "登录失败" });
      } else {
        res.send({ code: 200, msg: "登录成功" });
      }
    }
  );
});
//暴露路由器对象
module.exports = router;
